package com.boco.raptor.subsystem.attempx.server.bo;

import java.util.*;
import com.boco.transnms.common.dto.base.BoActionContext;
import com.boco.transnms.common.dto.misc.WfAttach;
import com.boco.transnms.common.dto.base.DboCollection;
import com.boco.transnms.common.dto.workflow.WfIdHref;
import com.boco.transnms.server.bo.base.AbstractBO;
import com.boco.raptor.subsystem.attempx.server.dao.AttempXWfGenericDAO;


public class AttempXWfGenericBO extends AbstractBO{
    public AttempXWfGenericBO(String boName){
        super(boName);
    }

    private static final String ATTACH_HREF_BASE = "/wmworkflow/attachFileDownload?attachId=";
    private static final String SIGN_HREF_BASE = "/wmworkflow/workmanager/showAuditSheet.do?signId=";

//    public List getHisEventList(WfBasicForm form) throws Exception{
//        IBoCommand cmd = BoCmdFactory.getInstance().createBoCmd(WorkFlowBOHelper.ActionName.getHisEventList, new Object[] {new BoActionContext(), form.getProcessKey()});
//        return (List)cmd.exec();
//    }

    public String saveAttachFile(BoActionContext dbContext, WfAttach dbo) throws Exception{
        return getGenericDAO().saveAttachFile(dbContext, dbo);
    }

    public WfAttach getAttachFile(BoActionContext dbContext, String attachId) throws Exception{
        return getGenericDAO().getAttachFile(dbContext, attachId);
    }

    public void delAttachFile(BoActionContext dbContext, String attachId) throws Exception{
        getGenericDAO().delAttachFile(dbContext, attachId);
    }
    public void updateAttachSheet(BoActionContext dbContext, String attachId) throws Exception{
       getGenericDAO().updateAttachSheet(dbContext, attachId);
   }

    public List getAttachIds(BoActionContext dbContext, String sheetId)throws Exception{
        return getGenericDAO().getAttachIds(dbContext, sheetId);
    }
    public List getAttachByCuid(BoActionContext dbContext,String cuid)throws Exception{
       return getGenericDAO().getAttachByCuid(dbContext,cuid);
   }
   public void modifyAttachByCuid(BoActionContext dbContext,String sql)throws Exception{
        getGenericDAO().modifyAttachByCuid(dbContext,sql);
   }


    public WfIdHref[] getAttachOutlines(BoActionContext dbContext, String attachIds[]) throws Exception{
        DboCollection dbc = getGenericDAO().getAttachOutlines(dbContext, attachIds);
        WfIdHref[] attachOutlines = new WfIdHref[0];
        if(dbc!=null && dbc.size()>0){
            attachOutlines = new WfIdHref[dbc.size()];
            WfAttach att = new WfAttach();
            for (int i = 0; i < attachOutlines.length; i++) {
                WfAttach dbo = (WfAttach) dbc.getAttrField(att.getClassName(), i);
                attachOutlines[i] = new WfIdHref(dbo.getCuid(), dbo.getAttachFileName(), ATTACH_HREF_BASE + dbo.getCuid(), "");
            }
        }
        return attachOutlines;
    }


    private AttempXWfGenericDAO getGenericDAO(){
        return new AttempXWfGenericDAO();
    }

}

